package com.zhz.company.controller;

import com.zhz.common.tool.mybatisplus.base.core.contract.BaseRequest;
import com.zhz.common.tool.mybatisplus.base.core.contract.Page;
import com.zhz.common.tool.mybatisplus.base.core.contract.R;
import com.zhz.company.biz.CompanyBizService;
import com.zhz.company.contract.request.CompanyDeleteRequest;
import com.zhz.company.contract.request.CompanyFindByIdRequest;
import com.zhz.company.contract.request.CompanySaveRequest;
import com.zhz.company.contract.request.CompanyUpdateRequest;
import com.zhz.company.contract.response.CompanyFindAllResponse;
import com.zhz.company.contract.response.CompanyFindByIdResponse;
import com.zhz.model.company.contract.param.CompanyQueryParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zhouhengzhe
 * @date 2023/3/22
 */
@Api(value="企业控制器",tags = "企业控制器")
@RestController
@RequestMapping("/company")
public class CompanyController {

    @Autowired
    private CompanyBizService companyBizService;

    @ApiOperation("保存企业")
    @PostMapping("/save")
    public R<Void> save(@RequestBody @Validated(BaseRequest.Save.class) CompanySaveRequest companySaveRequest) {
        companyBizService.add(companySaveRequest);
        return R.ok();
    }

    @ApiOperation("根据id更新企业")
    @PostMapping("/update")
    public R<Void> update(@RequestBody @Validated(BaseRequest.Update.class) CompanyUpdateRequest companyUpdateRequest) {
        companyBizService.update(companyUpdateRequest);
        return R.ok();
    }
    
    @ApiOperation("根据id删除企业")
    @PostMapping("/delete")
    public R<Void> delete(@RequestBody @Validated(BaseRequest.Delete.class) CompanyDeleteRequest companyDeleteRequest) {
        companyBizService.deleteById(companyDeleteRequest);
        return R.ok();
    }

    @ApiOperation("根据id查询企业")
    @PostMapping("findById")
    public R<CompanyFindByIdResponse> findById(@RequestBody @Validated CompanyFindByIdRequest companyFindByIdRequest) {
        return R.ok(companyBizService.findById(companyFindByIdRequest));
    }

    @ApiOperation("查询全部企业列表")
    @PostMapping("/findAll")
    public R<CompanyFindAllResponse> findAll() {
        return R.ok(companyBizService.findAll());
    }

    @ApiOperation("分页查询全部企业列表")
    @PostMapping("/page")
    public R<Page<CompanyFindByIdResponse>> page(@RequestBody CompanyQueryParam companyQueryParam) {
        return R.ok(companyBizService.page(companyQueryParam));
    }
}